
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>错误调试 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="API 参考" href="../ref/index.html" />
    <link rel="prev" title="FAQ：贡献代码" href="contributing.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="contributing.html" title="FAQ：贡献代码">previous</a>
     |
    <a href="index.html" title="Django FAQ" accesskey="U">up</a>
   |
    <a href="../ref/index.html" title="API 参考">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="faq-troubleshooting">
            
  <div class="section" id="s-troubleshooting">
<span id="troubleshooting"></span><h1>错误调试<a class="headerlink" href="#troubleshooting" title="永久链接至标题">¶</a></h1>
<p>本页包含了开发Django应用过程中一些常见错误和问题的处理建议。</p>
<div class="section" id="s-problems-running-django-admin">
<span id="s-troubleshooting-django-admin"></span><span id="problems-running-django-admin"></span><span id="troubleshooting-django-admin"></span><h2>运行 <code class="docutils literal notranslate"><span class="pre">django-admin</span></code> 时遇到的问题<a class="headerlink" href="#problems-running-django-admin" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-command-not-found-django-admin">
<span id="command-not-found-django-admin"></span><h3><code class="docutils literal notranslate"><span class="pre">command</span> <span class="pre">not</span> <span class="pre">found:</span> <span class="pre">django-admin</span></code><a class="headerlink" href="#command-not-found-django-admin" title="永久链接至标题">¶</a></h3>
<p>如果你是通过 <code class="docutils literal notranslate"><span class="pre">pip</span></code> 安装 Django 的，<a class="reference internal" href="../ref/django-admin.html"><span class="doc">django-admin</span></a> 应该在你的系统路径中。如果它不在你的路径中，请确保你已经激活了你的虚拟环境，你可以尝试运行等效的命令 <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">django</span></code>。</p>
</div>
<div class="section" id="s-macos-permissions">
<span id="macos-permissions"></span><h3>macOS 的权限问题<a class="headerlink" href="#macos-permissions" title="永久链接至标题">¶</a></h3>
<p>如果你正在使用 macOS，你可能看到“permission denied”提示，当你尝试运行``django-admin``的时候。这是因为在像 macOS 这种类Unix系统中，一个文件在它被当作程序执行之前必须被标记为“可执行”。为了解决这个问题，打开终端并且进入 <span class="xref std std-doc">django-admin `的安装目录（使用``cd``命令），然后执行命令``sudo chmod +x django-admin`</span>.</p>
</div>
</div>
<div class="section" id="s-miscellaneous">
<span id="miscellaneous"></span><h2>杂项<a class="headerlink" href="#miscellaneous" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong">
<span id="i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong"></span><h3>我遇到了错误信息 <code class="docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code>。 我哪里做错了？<a class="headerlink" href="#i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong" title="永久链接至标题">¶</a></h3>
<p>当包含非ASCII序列的字符串被转换为Unicode字符串，并且指定的编码不正确时，会发生此类错误。 输出一般看起来像这样:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ne">UnicodeDecodeError</span><span class="p">:</span> <span class="s1">&#39;ascii&#39;</span> <span class="n">codec</span> <span class="n">can</span><span class="s1">&#39;t decode byte 0x?? in position ?:</span>
<span class="n">ordinal</span> <span class="ow">not</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">128</span><span class="p">)</span>
</pre></div>
</div>
<p>解决方案主要取决于上下文，但是这里有两个常见的陷阱产生这个错误：</p>
<ul class="simple">
<li>您的系统语言环境可能是默认的ASCII，比如类UNIX系统上的 “C” （可通过命令 <code class="docutils literal notranslate"><span class="pre">locale</span></code> 进行检查）。如果是这种情况，请参考您的系统文档以了解如何将其更改为UTF-8语言环境。</li>
</ul>
<p>关联资源：</p>
<ul class="simple">
<li>：文档：<cite>Django 中的 Unicode&lt;/ref/unicode&gt;</cite></li>
<li><a class="reference external" href="https://wiki.python.org/moin/UnicodeDecodeError">https://wiki.python.org/moin/UnicodeDecodeError</a></li>
</ul>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">错误调试</a><ul>
<li><a class="reference internal" href="#problems-running-django-admin">运行 <code class="docutils literal notranslate"><span class="pre">django-admin</span></code> 时遇到的问题</a><ul>
<li><a class="reference internal" href="#command-not-found-django-admin"><code class="docutils literal notranslate"><span class="pre">command</span> <span class="pre">not</span> <span class="pre">found:</span> <span class="pre">django-admin</span></code></a></li>
<li><a class="reference internal" href="#macos-permissions">macOS 的权限问题</a></li>
</ul>
</li>
<li><a class="reference internal" href="#miscellaneous">杂项</a><ul>
<li><a class="reference internal" href="#i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong">我遇到了错误信息 <code class="docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code>。 我哪里做错了？</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="contributing.html"
                        title="上一章">FAQ：贡献代码</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="../ref/index.html"
                        title="下一章">API 参考</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/faq/troubleshooting.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="contributing.html" title="FAQ：贡献代码">previous</a>
     |
    <a href="index.html" title="Django FAQ" accesskey="U">up</a>
   |
    <a href="../ref/index.html" title="API 参考">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>